﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sis.Entities;

namespace Sis.Repository
{
    public class PromotorRepository : MasterRepository, IPromotorRepository
    {
        public List<Promotor> GetFroPromorByCriterio(string criterio)
        {
            var query = from p in Context.Promotors
                select p;
            if (criterio!=null && criterio!=string.Empty && criterio!="")
            {
                query = from p in query
                    where p.Nombres.ToUpper().Contains(criterio.ToUpper()) ||
                          p.ApPaterno.ToUpper().Contains(criterio.ToUpper()) ||
                          p.ApMaterno.ToUpper().Contains(criterio.ToUpper()) ||
                          p.Dni.ToUpper().Contains(criterio.ToUpper())
                    select p;
            }
            return query.ToList();
        }

        public void AddPromotor(Promotor promotor)
        {
            Context.Promotors.Add(promotor);
            Context.SaveChanges();
        }


        public Promotor promotorByID(int id)
        {
            return Context.Promotors.Find(id);
        }

        public List<Promotor> GetPromotores()
        {
            var query = from p in Context.Promotors
                select p;
            return query.ToList();
        }
    }
}
